<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>返回一个表单中所有元素的value</title>
</head>

<body>
    <form id="myForm" action="/">
        name: <input type="text" name="fname" value="RUNOOB"><br>
        url: <input type="text" name="lname" value="www.runoob.com"><br>
        <input type="submit" value="提交按钮">
    </form>
    <p>点击按钮返回表单中每个元素的值：<button onclick="myFunction()">点我</button></p>
    <p id="demo"></p>
    <script>
        function myFunction() {
            var x = document.getElementById("myForm");
            var txt = "";
            var i;
            for (i = 0; i < x.length; i++) {
                txt = txt + x.elements[i].value + "<br>";
            }
            document.getElementById("demo").innerHTML = txt;
        }
    </script>
</body>

</html>